import {getFileType} from "../../../utils/index.js";

var vm = new Vue({
    el: '#app',
    data: {
        dialogVisible: false,
        buttonLoading: false,
        uploadAction: context + `ICDImportConfig/importIcd`,
        tableData: [],
        total: 50,
        page_size: 5,
        current_page: 1
    },
    methods: {
        //打开弹窗
        showDialog() {
            this.dialogVisible = true
        },
        beforeUpload(file) {
            const type = getFileType(file.name)
            if (type !== 'icd') {
                this.$message({
                    message: "只支持icd类型文件",
                    type: 'error'
                })
                return false
            } else {
                return true
            }
        },
        uploadError(e) {
            this.$message({
                message: e.message,
                type: 'error'
            })
            NProgress.done()
            vm.getConfigList();
            this.dialogVisible = false
            this.buttonLoading = false
        },
        uploadSuccess() {
            NProgress.done()
            vm.getConfigList();
            this.dialogVisible = false
            this.buttonLoading = false
        },
        uploadProgress() {
            this.buttonLoading = true
            NProgress.start()
        },
        // addMenu: function () {
        //     layer.open({
        //         type: 2,
        //         title: '新增',
        //         maxmin: true,
        //         shadeClose: false, // 点击遮罩关闭层
        //         area: ['800px', '520px'],
        //         content: context + 'menu/add',
        //         end: function () {
        //             vm.getMenuList();
        //         }
        //     });
        // },
        handleEdit: function (row) {
            layer.open({
                type: 2,
                title: '编辑',
                maxmin: true,
                shadeClose: false, // 点击遮罩关闭层
                area: ['800px', '520px'],
                content: context + 'ICDImportConfig/update?id=' + row.id,
                end: function () {
                    vm.getConfigList();
                }
            });
        },
        handleConfig: function (row) {
            layer.open({
                type: 2,
                title: '编辑',
                maxmin: true,
                shadeClose: false, // 点击遮罩关闭层
                area: ['800px', '520px'],
                content: context + 'ICDImportConfig/remoteUploadConfig?id=' + row.iedName,
                end: function () {
                    vm.getConfigList();
                }
            });
        },

        handleDelete: function (row) {
            layer.confirm("您确定要删除吗？", function (index) {
                $.ajax({
                    url: context + 'ICDImportConfig/deleteConfig?id=' + row.id,
                    type: 'GET',
                    success: function (res) {
                        if (res.code === 200) {
                            if (res.data.code === 200) {
                                layer.msg("操作成功");
                                vm.getConfigList();
                            } else {
                                layer.msg("操作失败");
                            }

                        }
                    }
                });
            });
        },
        formatShow: function (row, column) {
            return row.iedState == true ? '启用' : '未启用';
        },
        handleSizeChange: function (val) {
            vm.page_size = val;
            this.getConfigList();
        },
        handleCurrentChange: function (val) {
            vm.current_page = val;
            this.getConfigList();
        },

        getConfigList: function () {
            $.ajax({
                url: context + 'ICDImportConfig/getConfigInfo?page=' + this.current_page + '&page_size=' + this.page_size,
                type: 'GET',
                success: function (res) {
                    console.log(res);
                    vm.tableData = res.data.sysConfigList;
                    vm.total = res.data.total;
                    vm.page_size = res.data.page_size;
                    vm.current_page = res.data.page;
                }
            });
        }

    },
    mounted: function () {
        this.getConfigList();
    }
});
